import http from './interface'

/**
 * 将业务所有接口统一起来便于维护
 * 如果项目很大可以将 url 独立成文件，接口分成不同的模块
 * 
 */
export const baseUrl =http.config.baseUrl;
// 单独导出(测试接口) import {test} from '@/common/vmeitime-http/'
export const test = (data) => {
	/* http.config.baseUrl = "http://localhost:8080/api/"
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
		}
	} */
	//设置请求结束后拦截器
	http.interceptor.response = (response) => {
		console.log('个性化response....')
		//判断返回状态 执行相应操作
		return response;
	}
    return http.request({
		baseUrl: 'https://unidemo.dcloud.net.cn/',
        url: 'ajax/echo/text?name=uni-app',
		dataType: 'text',
        data,
    })
}

// 轮播图
export const banner = (data) => {
    return http.request({
        url: '/slideshow/selectallslideshow.action',
        method: 'GET', 
        data,
		// handle:true
    })
}
// 注册获取验证码
export const getCode = (data) => {
    return http.request({
        url: '/userl/phoneverify.action',
        method: 'POST', 
        data,
		// handle:true
    })
}
// 注册
export const register = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('regToken')
		}
	}
    return http.request({
        url: '/userl/phoneudsht.action',
        method: 'POST', 
        data,
		// handle:true
    })
}
// 登陆
export const appLogin = (data) => {
    return http.request({
        url: '/userl/login.action',
        method: 'POST', 
        data,
    })
}
// 首页分类进入商品列表
export const searchType = (data) => {
    return http.request({
        url: '/products/selectbyptype.action',
        method: 'POST', 
        data,
    })
}
// 首页查询分类
export const searchIcon = (data) => {
    return http.request({
        url: '/ptypes/selectallptypes.action',
        method: 'GET', 
        data,
    })
}
// 首页热卖产品
export const hotSale = (data) => {
    return http.request({
        url: '/products/selectremi.action',
        method: 'GET', 
        data,
    })
}
// 模糊搜索
export const searchKey = (data) => {
    return http.request({
        url: '/products/selectprolist.action',
        method: 'POST', 
        data,
    })
}
// 规格搜索查询
export const selectbyslrlm = (data) => {
    return http.request({
        url: '/products/selectbyslrlm.action ',
        method: 'POST', 
        data,
    })
}
// 一级分类
export const stairClass = (data) => {
    return http.request({
        url: '/specification/selectspelist.action',
        method: 'GET', 
        data,
    })
}
// 二级分类
export const secondClass = (data) => {
    return http.request({
        url: '/standards/selectstanbysid.action',
        method: 'GET', 
        data,
    })
}
// 商品详情
export const proDetails = (data) => {
    return http.request({
        url: '/products/selectByPrimaryKey.action',
        method: 'POST', 
        data,
    })
}
// 添加商品到购物车
export const goCarts = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('userInfo').token
		}
	}
    return http.request({
        url: '/charts/insertSelective.action',
        method: 'POST', 
        data,
    })
}
// 商品评价
export const evaluate = (data) => {
    return http.request({
        url: '/orderdetails/selectpidadvices.action',
        method: 'POST', 
        data,
    })
}

// 地址管理查询
export const getAddress = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('userInfo').token
		}
	}
    return http.request({
        url: '/address/selectaddbyuserid.action',
        method: 'GET', 
        data,
    })
}
// 添加地址
export const addAddress = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('userInfo').token
		}
	}
    return http.request({
        url: '/address/insertSelective.action',
        method: 'POST', 
        data,
    })
}
// 修改地址
export const updateAddress = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('userInfo').token
		}
	}
    return http.request({
        url: '/address/updateByPrimaryKeySelective.action',
        method: 'POST', 
        data,
    })
}
// 删除地址
export const delAddress = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('userInfo').token
		}
	}
    return http.request({
        url: '/address/deleteByPrimaryKey.action',
        method: 'GET', 
        data,
    })
}
// 删除地址
export const updatePassWord = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('userInfo').token
		}
	}
    return http.request({
        url: '/userl/updateuserlpwd.action',
        method: 'POST', 
        data,
    })
}
// 修改手机号
export const updatePhone = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('userInfo').token
		}
	}
    return http.request({
        url: '/userl/updateuserl.action',
        method: 'POST', 
        data,
    })
}
// 查询购物车
export const cartSearch = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('userInfo').token
		}
	}
    return http.request({
        url: '/charts/selectchartslist.action',
        method: 'POST', 
        data,
    })
}

// 删除购物车
export const cartDelete = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('userInfo').token
		}
	}
    return http.request({
        url: '/charts/deleteByPrimaryKey.action',
        method: 'POST', 
        data,
    })
}
// 增减购物车
export const cartCount = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('userInfo').token
		}
	}
    return http.request({
        url: '/charts/updateByPrimaryKeySelective.action',
        method: 'POST', 
        data,
    })
}
// 购物车去结算单
export const statement = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('userInfo').token
		}
	}
    return http.request({
        url: '/charts/selectchartsli.action',
        method: 'POST', 
        data,
    })
}
// 查询订单 
export const searchOrder = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('userInfo').token
		}
	}
    return http.request({
        url: '/orderis/selectlists.action',
        method: 'POST', 
        data,
    })
}
// 提交订单
export const creatOrder = (data) => {
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": uni.getStorageSync('userInfo').token
		}
	}
    return http.request({
        url: '/orderis/insertSelective.action',
        method: 'POST', 
        data,
    })
}

// 默认全部导出  import api from '@/common/vmeitime-http/'
export default {
	baseUrl,
    banner,getCode,register,appLogin,searchType,searchKey,stairClass,secondClass,proDetails,evaluate,getAddress,addAddress,updateAddress,delAddress,updatePassWord,updatePhone,cartSearch,hotSale,selectbyslrlm,searchIcon,goCarts,cartDelete,cartCount,searchOrder,statement,creatOrder
}